package org.c4s.algorithm.cluster;

import org.c4s.algorithm.cluster.DataPoint;
import org.c4s.algorithm.cluster.JCA;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Vector;
import java.util.Iterator;

/**
 * Created by IntelliJ IDEA. User: shyam.s Date: Apr 18, 2004 Time: 4:26:06 PM
 */

public class PrgMain {
	public static void main(String args[]) throws IOException {
		ArrayList<Integer> memCluster = new ArrayList<Integer>();
		String line = "";
		int sum = 0;
		int count = 0, mem = 0;
		double ele1, ele2, ele3, ele4 = 0.0;
		String[] temp = null;
		Vector dataPoints = new Vector();
		Vector tempV = new Vector();

		FileReader input = new FileReader("C:/Users/Beelzebo/Desktop/iris.txt");
		BufferedReader bufRead = new BufferedReader(input);
		while (line != null) {
			line = bufRead.readLine();
			sum = count;
			count++;
			if (line != null) {
				temp = line.split(",");
			} else {
				break;
			}
			ele1 = Double.parseDouble(temp[0]);
			ele2 = Double.parseDouble(temp[1]);
			ele3 = Double.parseDouble(temp[2]);
			ele4 = Double.parseDouble(temp[3]);
			dataPoints
					.add(new DataPoint(count, ele1, ele2, ele3, ele4, temp[4]));
		}
		Iterator iter;
		JCA jca = new JCA(4, 1000, dataPoints);
		jca.startAnalysis();

		Vector[] v = jca.getClusterOutput();

		for (int i = 0; i < v.length; i++) {
			// tempV = v[i];
			// System.out.print(v[i].size()+"\n");
			memCluster.add(v[i].size());

		}

		for (int i = 0; i < v.length; i++) {
			tempV = v[i];
			System.out.println("\n-----------Cluster" + i
					+ "------------------");
			System.out.println("The number of member cluster " + i + " : "
					+ memCluster.get(i));
			System.out.println("Population : "
					+ (memCluster.get(i).doubleValue() * 100) / sum + "%");
			System.out.println("-------------------------------------");
			iter = tempV.iterator();
			while (iter.hasNext()) {
				DataPoint dpTemp = (DataPoint) iter.next();
				System.out.println("Line " + dpTemp.getCount() + " : "
						+ dpTemp.getObjName() + "[" + dpTemp.getW() + ","
						+ dpTemp.getX() + "," + dpTemp.getY() + ","
						+ dpTemp.getZ() + "]");
			}
		}
	}
}